<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function gretting(...args){
            return `hello,I am ${this.name}`
        }
        Function.prototype.myCall = function(context,...args){
            console.log('////');
            if(context === null || context === undefined){
                context = window
            }
            //this 指向调用的函数
            if(typeof this !=='function'){
                throw new TypeError('Function.prototype.myCall called on non-function')
            }
            //函数要运行
            //Symbol es6的新数据类型 唯一绝对不会重复
            const fnKey = Symbol('fn')
            // this 运行 函数内部的this要指向context
            // this 是 context 上面的方法的时候
            // 不要覆盖 context 上面的属性
            context[fnKey] = this;
            //收集参数
            const result = context[fnKey](...args);
            //context 被污染了
            delete context[fnKey]
            return result
        }
        var obj = {
            name:'lj',
            fn:function(){

            }
        }
        gretting.myCall(obj,1,2,3)
    </script>
</body>
</html>